//
//  BaseViewController.m
//  VirtualCurrency
//
//  Created by apple on 2021/7/5.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@end

@implementation BaseViewController

- (void) addTitleBarWithBackBtn:(NSString *)title needReturn:(bool)need{

    _titlebar= [[UIView alloc]initWithFrame:CGRectMake(0, 0, IDWidth, naviH)];
    _titlebar.backgroundColor = [UIColor whiteColor];
    _lableTitle = [[UILabel alloc]initWithFrame:CGRectMake(40.0f, kTitleLabelHeight, IDWidth-80, 40)];
    _lableTitle.text = title;
    _lableTitle.textAlignment = NSTextAlignmentCenter;
    _lableTitle.textColor = [UIColor whiteColor];
    _lableTitle.backgroundColor = [UIColor clearColor];
    _lableTitle.font = [UIFont systemFontOfSize:18.0];
    [_titlebar addSubview:_lableTitle];
    
    if(need){
        UIImage *hamburger = [UIImage imageNamed:@"icon_黑色_返回.png"];
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _backBtn.frame = CGRectMake(10.0f, 28 + kPoorWithiPhoneX, 25.0f, 30.0f);
        [_backBtn setImage:hamburger forState:UIControlStateNormal];
        [_backBtn addTarget:self action:@selector(btnBack) forControlEvents:UIControlEventTouchUpInside];
        [_titlebar addSubview:_backBtn];
        [self addBackGesture:YES];
    }
    
    
    [self.view addSubview:_titlebar];
    
}
//设置首页的导航条
- (void) addTitleBarWithBackBtn:(NSString *)title{
    [self addTitleBarWithBackBtn:title needReturn:NO];
}


//返回上一级页面
- (void)addBackGesture:(bool)need{
    UISwipeGestureRecognizer *rightSwipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(btnBack)];
    rightSwipeGestureRecognizer.direction = UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:rightSwipeGestureRecognizer];
    // 一定要禁止系统自带的滑动手势
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
- (void)btnBack {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = bGColor;
    UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipeFrom)];
    [recognizer setDirection:(UISwipeGestureRecognizerDirectionDown)];
    [self.view addGestureRecognizer:recognizer];
    
    // Do any additional setup after loading the view.
}
-(void)handleSwipeFrom{
    [self.view endEditing:YES];
}
//列表横线隐藏
- (void)setExtraCellLineHidden: (UITableView *)tableView{
    UIView *view =[ [UIView alloc]init];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
    [tableView setTableHeaderView:view];
}
#pragma mark - close keyboard
- (void)colseKeyboard{
    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
